package com.kly.user.db.dao.impl;
import com.fqgj.common.base.AbstractBaseMapper;
import com.google.common.collect.Maps;
import com.kly.user.db.dao.UserChatterMappingDao;
import com.kly.user.db.entity.UserChatterMappingEntity;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Map;

/**
* User: linqu
* Date: 2023-06-21
* Time: 10:44:30.534
*/

@Repository
public class UserChatterMappingDaoImpl extends AbstractBaseMapper<UserChatterMappingEntity> implements UserChatterMappingDao {

    @Override
    public List<UserChatterMappingEntity> queryByChatterUserCode(String chatterUserCode) {
        Map<String, Object> params = Maps.newHashMap();
        params.put("chatterUserCode", chatterUserCode);
        params.put("status", 1);
        params.put("deleted", 0);
        return this.selectByParams(params);
    }

    @Override
    public List<UserChatterMappingEntity> queryByModelUserCode(String modelCode) {
        Map<String, Object> params = Maps.newHashMap();
        params.put("modelUserCode", modelCode);
        params.put("status", 1);
        params.put("deleted", 0);
        return this.selectByParams(params);
    }

    @Override
    public List<UserChatterMappingEntity> queryByChatterUserCodes(List<String> chatterCodes) {
        Map<String, Object> params = Maps.newHashMap();
        params.put("chatterCodes", chatterCodes);
        return this.getSqlSession().selectList(this.getStatement("queryByChatterUserCodes"), params);
    }

    @Override
    public List<UserChatterMappingEntity> queryByModelUserCodes(List<String> userCodes) {
        Map<String, Object> params = Maps.newHashMap();
        params.put("userCodes", userCodes);
        return this.getSqlSession().selectList(this.getStatement("queryByModelUserCodes"), params);
    }

    @Override
    public List<UserChatterMappingEntity> queryByModelUserCode(String fromUserCode, String toUserCode) {
        Map<String, Object> params = Maps.newHashMap();
        params.put("modelUserCode", fromUserCode);
        params.put("modelUserCode2", toUserCode);
        return this.getSqlSession().selectList(this.getStatement("queryByModelUserCode"), params);
    }

    @Override
    public void deleteByModelUserCode(String modelUserCode) {
        Map<String, Object> params = Maps.newHashMap();
        params.put("modelUserCode", modelUserCode);
        this.getSqlSession().update(this.getStatement("deleteByModelUserCode"),params);
    }

    @Override
    public void deleteByChatUserCode(String chatterUserCode) {
        Map<String, Object> params = Maps.newHashMap();
        params.put("chatterUserCode", chatterUserCode);
        this.getSqlSession().update(this.getStatement("deleteByChatUserCode"),params);
    }

    @Override
    public List<UserChatterMappingEntity> queryAllChatters() {
        Map<String, Object> params = Maps.newHashMap();
        params.put("deleted", 0);
        params.put("status", 1);
        return selectByParams(params);
    }

    @Override
    public List<String> selectAll(String chatterUserCode) {
        Map<String, Object> params = Maps.newHashMap();
        params.put("chatterUserCode", chatterUserCode);
        return this.getSqlSession().selectList(this.getStatement("selectAll"),params);
    }


    @Override
    public List<UserChatterMappingEntity> queryByChatterAccount(String chatterAccount) {
        Map<String, Object> params = Maps.newHashMap();
        if (StringUtils.isNotEmpty(chatterAccount)) {
            params.put("chatterAccount", chatterAccount);
        }
        params.put("status", 1);
        params.put("deleted", 0);
        return this.selectByParams(params);
    }

    @Override
    public List<UserChatterMappingEntity> selectAllChatters() {
        return this.getSqlSession().selectList(this.getStatement("selectAllChatters"));
    }

}